﻿var sortType = "DESC";
var sortField = "ROUTE_HOT";
var currentPage = 1;
var filter = { key: "", val: "" };



function getRoutesByCountry(countryName) {
    getRoutesByFilter("ROUTE_COUNTRY_NAME", countryName, initPageSelecter);
}

function getRoutesByTheme(themeId) {
    getRoutesByFilter("THEME_ID", themeId, initPageSelecter);
}

function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
}

function getRoutesByFilter(key, val,initPage) {

    filter = { "key": key, "val": val, "sortType": sortType, "sortField": sortField, "pageNo": currentPage };
    $.post("../Handler/RouteFilter.ashx", filter,
        function (routes) {
            if (!routes) return;

            _currentRoutesResult = routes;
            initPage();
            $("#routeList").empty();
            var innerHTML = "";
            $.each(routes, function (idx, route) {
                if (idx > 4) return;    //初次加载 5个
                innerHTML += "<div class=\"theList\">";
                innerHTML += "        <div class=\"listContent\">";
                innerHTML += "            <div class=\"listPic floatL\">";
                innerHTML += "                <img src=\"" + route.Cover + "\" width=\"300\" height=\"250\" alt=\"\" />";
                innerHTML += "            </div>";
                innerHTML += "            <div class=\"listText floatR\">";
                innerHTML += "                <ul>";
                innerHTML += "                    <li class=\"h22\">" + route.ROUTE_NAME + "</li>";
                innerHTML += "                    <li class=\"h4 fontcolb9 lineh20 marginT20 marginB40\">" + route.ROUTE_DES + "<br />";
                innerHTML += "                        旅行主题：" + route.ThemeString + "<br />";
                //innerHTML += "                        出发日期：" + route.ROUTE_DATE_START_SHORT + "/" + route.ROUTE_DATE_END_SHORT + "...</li>";
                innerHTML += "                        途经城市：" + route.Citys + "</li>";
                innerHTML += "                    <li class=\"h4 fontcolb9 lineh20 noDisplay\">" + route.ROUTE_BAK + "</li>";
                innerHTML += "                    <li class=\"fontcolfc3\">";
                innerHTML += "                        <div class=\"floatL noDisplay\"><span class=\"h1\">" + route.ROUTE_PRICE + "</span>RMB/人起</div>";
                innerHTML += "                        <div class=\"floatR\">";
                innerHTML += "                            <a href=\"" + route.ROUTE_ID + ".html\">";
                innerHTML += "                                <img src=\"images/linkDdetails.png\" width=\"126\" height=\"27\" alt=\"\" /></a>";
                innerHTML += "                        </div>";
                innerHTML += "                    </li>";
                innerHTML += "                </ul>";
                innerHTML += "            </div>";
                innerHTML += "        </div>";
                innerHTML += "    </div>";
                innerHTML += "  <div class=\"clear\"></div>";
            });
            //alert(routes.length);
            $("#routeCount").html(routes.length);
            $("#routeList").html(innerHTML);
        }, "json");
}